package com.tangcl.tclmvvm.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.Navigation
import com.tangcl.module_commom.base.BaseFragment
import com.tangcl.tclmvvm.R
import kotlinx.android.synthetic.main.activity_main.*

private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [HomeFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class HomeFragment : BaseFragment() {
    private var param1: String? = null
    private var param2: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_home
    }

    companion object {
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            HomeFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }

    override fun setListener() {
//        skipToFragment()
    }

    private fun skipToFragment(view: View) {
        val navController = Navigation.findNavController(view)
        navController.navigate(R.id.action_homeFragment_to_mineFragment)

        //普通方式传递参数
        //val bundle = Bundle()
        //bundle.putString("key", "test")
        //navController.navigate(R.id.action_navFragmentA_to_navFragmentB,bundle)
        //navController.navigate(R.id.action_navFragmentA_to_navFragmentB)

        //safeArgs传递参数
        //在项目和app的build.gradle下添加该插件，在nav_graph.xml的design模式下添加参数，rebuild
        //val navDestination = NavFragmentADirections.actionNavFragmentAToNavFragmentB("navigation test")
        //navController.navigate(navDestination)
    }

}